#include <interface/window.h>
#include <interface/gl.h>
#include <interface/font.h>
#include <interface/resman.h>

#include "mainWin.h"
#include "testWin.h"

#include <iostream>

#include <interface/timer.h>

int WINAPI WinMain(	HINSTANCE,				// Instance
			HINSTANCE,				// Previous Instance
			LPSTR,				// Command Line Parameters
			int)				// Window Show State
{

	MSG	msg;								// Windows Message Structure
	BOOL	done=FALSE;							// Bool Variable To Exit Loop

	win = new mainWin();
    //tstwin = new testWin();

	while(!done)								// Loop That Runs Until done=TRUE
	{
		while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))			// Is There A Message Waiting?
		{
			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?
			{
				done=TRUE;					// If So done=TRUE
			}
			else							// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
        if (win){
            if (win->isActive())
            {
                if (win->getInput()->getKey(VK_ESCAPE))
                {
                    done=TRUE;
                }
                else
                {
                    win->elEventExec();
                    win->display();
                }
                win->updateMgr();
            }
            if( !win ) continue;
            if (win->getInput()->bindKey(VK_F1))
            {
                win->setFullscreen(!(win->isFullscreen()));
                if( win->isFullscreen() ) win->adaptToScreenSize();
                win->recreate();
                ((mainWin*)win)->getFont()->reload();
            }
            if (win->getInput()->bindKey(VK_F5))
            {
                ((mainWin*)win)->getFont()->setBold( !((mainWin*)win)->getFont()->isBold() );
                ((mainWin*)win)->getFont()->reload();
            }
            if (win->getInput()->bindKey(VK_F6))
            {
                ((mainWin*)win)->getFont()->setStroke( !((mainWin*)win)->getFont()->isStroke() );
                ((mainWin*)win)->getFont()->reload();
            }
            if (win->getInput()->bindKey(VK_F7))
            {
                ((mainWin*)win)->getFont()->setItalic( !((mainWin*)win)->getFont()->isItalic() );
                ((mainWin*)win)->getFont()->reload();
            }
            if (win->getInput()->bindKey(VK_F8))
            {
                ((mainWin*)win)->getFont()->setUnderline( !((mainWin*)win)->getFont()->isUnderline() );
                ((mainWin*)win)->getFont()->reload();
            }
        }
        if (tstwin){
            if (!tstwin->isCreated()){
                    delete tstwin;
                    tstwin = NULL;
                    continue;
            }
            if (tstwin->isActive())
            {
                tstwin->display();
                if( !tstwin ) continue;
                tstwin->elEventExec();
                tstwin->updateMgr();
            }
            if (tstwin->getInput()->bindKey(VK_F5))
            {
                ((testWin*)tstwin)->getFont()->setBold( !((testWin*)tstwin)->getFont()->isBold() );
                ((testWin*)tstwin)->getFont()->reload();
            }
            if (tstwin->getInput()->bindKey(VK_F6))
            {
                ((testWin*)tstwin)->getFont()->setStroke( !((testWin*)tstwin)->getFont()->isStroke() );
                ((testWin*)tstwin)->getFont()->reload();
            }
            if (tstwin->getInput()->bindKey(VK_F7))
            {
                ((testWin*)tstwin)->getFont()->setItalic( !((testWin*)tstwin)->getFont()->isItalic() );
                ((testWin*)tstwin)->getFont()->reload();
            }
            if (tstwin->getInput()->bindKey(VK_F8))
            {
                ((testWin*)tstwin)->getFont()->setUnderline( !((testWin*)tstwin)->getFont()->isUnderline() );
                ((testWin*)tstwin)->getFont()->reload();
            }
        }
	}
	delete win;
	return (msg.wParam);
}

